/*
CpGears v1.0

Copyright (c) 2010 Yves Riel http://www.flash-factor.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

package cpgears 
{
	import cpgears.helpers.CaptivateHelper;
	import cpgears.properties.IWidgetProperties;
	import cpgears.views.manager.IWidgetViewManager;
	import flash.display.MovieClip;
	import flash.external.ExternalInterface;
	
	/**
	 * Implements a Captivate Interactive Widget
	 * 
	 * @author Whyves
	 */
	public class InteractiveWidget extends WidgetBase implements IInteractive
	{
		
		// Reference to the Interactive MovieClip API passed by Captivate.
		private var mInteractiveClip:MovieClip = null;
		
		/**
		 * Creates an Interactive Widget.
		 * 
		 * @param	widgetProperties The property object that will be passed to Captivate to store the widget parameters.
		 * @param	widgetViewManager A manager that will handle which view to display during a specific widget phase.
		 */
		public function InteractiveWidget(widgetProperties:IWidgetProperties = null, widgetViewManager:IWidgetViewManager = null) 
		{
			super(widgetProperties, widgetViewManager);
			initializeInterface();
		}
		
		/**
		 * @private
		 */
		private function initializeInterface():void {
			if (ExternalInterface.available) {
				CaptivateHelper.addExternalInterface("isInteractive", isInteractive);
			}			
		}
		
		/**
		 * @private
		 */
		private function isInteractive():Boolean {
			return true;
		}
		
		/**
		 * Internal properties required by Captivate.
		 * 
		 * <p>At runtime, Captivate passed an Interactive Widget a reference to the Interactive API.
		 * developers should ingnore this variable as it's purely a CpGears internal variable that must
		 * be public in order for an Interactive Widget to be functional.</p>
		 */
		public function get interactiveWidget_mc():MovieClip {
			return mInteractiveClip;
		}
		public function set interactiveWidget_mc(value:MovieClip):void {
			mInteractiveClip = value;
		}
		
		/**
		 * @inheritDoc
		 */
		public function setSuccess():void {
			mInteractiveClip.setSuccess(true);
		}

		/**
		 * @inheritDoc
		 */
		public function setFailure():void {
			mInteractiveClip.setSuccess(false);
		}
		
		/**
		 * @inheritDoc
		 */
		public function showHint():void {
			mInteractiveClip.setShowHint();
		}
		
		/**
		 * @inheritDoc
		 */
		public function hideHint():void 
		{
			mInteractiveClip.setHideHint();
		}
	}
}